
/**
 * Demonstrates a range of Button options the framework offers out of the box
 */
Ext.define('cloud.view.role.PowerAdd', {
    extend: 'Ext.form.Panel',
    xtype: 'powerAdd',
    requires: [
        'Ext.form.Panel',
        'Ext.form.FieldSet',
        'Ext.field.Select',
        'Ext.Img'
    ],
    config: {
        title:'添加权限',
        items:[
            {
                xtype: 'toolbar',
                docked: 'bottom',
                layout: {
                    type: 'hbox',
                    pack: 'end'
                },
                items: [
                    {
                        id: 'power_submit',
                        iconMask: true,
                        cls:'x-button2',
                        scope: this,
                        text: '提交',
                        style: 'float:right'
                    }
                ]
            },
            {
                xtype: 'textfield',
                name:'rid',
                id: 'power_rid_add',
                hidden:true
            },
            {
                xtype: 'toolbar',
                ui: 'dark',
                docked: 'top',
                items: [
                    {
                        xtype: 'selectfield',
                        store: 'AreaAllFindStore',
                        displayField: 'name',
                        id:'power_cadid_add',
                        valueField: 'cadid',
                        listeners:{
                            change: function (item,newValue,oldValue) {
                                Ext.Viewport.mask({xtype: 'loadmask'});
                                var rid = Ext.getCmp('power_rid_add').getValue()
                                Ext.Ajax.request({
                                    url: GLOBAL.api_url + 'role_purview_not_select',
                                    params: {
                                        caid:localStorage.getItem('caid'),
                                        rid:rid,
                                        cadid:newValue
                                    },
                                    scope: this,
                                    success: function (response) {
                                        Ext.Viewport.unmask();
                                        var result = Ext.decode(response.responseText);
                                        var checkboxs = [];
                                        var data = result.Variables.data;
                                        for (var i = 0; i < data.length; i++) {
                                            checkboxs.push(
                                                {
                                                    layout: 'hbox',
                                                    items: [
                                                        {
                                                            style: '-webkit-box-orient: horizontal;',
                                                            xtype: 'checkboxfield',
                                                            name: 'unPower_id',
                                                            label: data[i].name,
                                                            value: data[i].id,
                                                            width:'100%',
                                                            labelWidth:'60%'
                                                        }
                                                    ]
                                                }
                                            );
                                        }
                                        Ext.getCmp('power_add_check').setItems(checkboxs);
                                    },
                                    failure: function () {
                                        Ext.Viewport.unmask();
                                        Ext.Msg.alert('服务器维护中...')
                                        return false;
                                    }
                                })
                            },
                            painted:function(eOpts ){
                                Ext.Viewport.mask({xtype: 'loadmask'});
                                var store = Ext.getStore('AreaAllFindStore');
                                store.load({params: {caid: localStorage.getItem('caid')}});
                                var cadid=this.getValue()
                                if(cadid!=null||cadid!=undefined){
                                    var rid = Ext.getCmp('power_rid_add').getValue()
                                    Ext.Ajax.request({
                                        url: GLOBAL.api_url + 'role_purview_not_select',
                                        params: {
                                            caid:localStorage.getItem('caid'),
                                            rid:rid,
                                            cadid:cadid
                                        },
                                        scope: this,
                                        success: function (response) {
                                            Ext.Viewport.unmask();
                                            var result = Ext.decode(response.responseText);
                                            var checkboxs = [];
                                            var data = result.Variables.data;
                                            for (var i = 0; i < data.length; i++) {
                                                checkboxs.push(
                                                    {
                                                        layout: 'hbox',
                                                        items: [
                                                            {
                                                                style: '-webkit-box-orient: horizontal;',
                                                                xtype: 'checkboxfield',
                                                                name: 'unPower_id',
                                                                label: data[i].name,
                                                                value: data[i].id,
                                                                width:'100%',
                                                                labelWidth:'60%'
                                                            }
                                                        ]
                                                    }
                                                );
                                            }
                                            Ext.getCmp('power_add_check').setItems(checkboxs);
                                        },
                                        failure: function () {
                                            Ext.Viewport.unmask();
                                            Ext.Msg.alert('服务器维护中...')
                                            return false;
                                        }
                                    })
                                }
                            }
                        }
                    }
                ]
            },
            {
                xtype:'fieldset',
                title:'添加权限',
                id:'power_add_check'
            }
        ]
    }
});